<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
	<table cellpadding="5" cellspacing="0" width="100%">
	<tr>
    	<td class="sp_home_title" width="100%">
      		 Tin Tức
        </td>

		</tr>
	</table>
	<div class="khung_sp_ds_top_c">
		<div class="khung_sp_tc_top_l"><img src="images/khung_sp_trangchu_top_l.gif" /></div>
		<div class="khung_sp_tc_top_r"><img src="images/khung_sp_trangchu_top_r.gif" /></div>
	</div>

	<div style="border:1px solid #ccc; background:#fff; border-top:none; padding:10px">

	<table style="padding:4px"></table>
	<table border="0" cellpadding="0" cellspacing="2">
		<?php
			$query2 = "SELECT * FROM newdetails";
			$result2 = mysql_query($query2);
			$total = mysql_num_rows($result2);
			$perPage = 10;
			$numOfPage = ceil($total/$perPage);
			
			if($_GET['pa'] =="")
			{
				$x = 0;
			}
			else
			{
				$x = ($_GET['pa'] - 1) * $perPage;
			}
		
            $query = "select * from newdetails where state='on' order by id DESC LIMIT $x,$perPage";
            $result = mysql_query($query) or die();
			$a=1;
            while($row = mysql_fetch_array($result)){?>
			<tr>
			
                <td>
                	<a href="index.php?page=newdetails&id=<?php echo $row['id'];?>"><img src="<?php echo substr($row['newImage'],3);?>" width="100" height="80" /></a>
                </td>
				<td width="5"></td>
               	<td>
                	<table border="0" cellpadding="0" cellspacing="2" width="100%">
                    	<tr>
                        	<td class="title_new">
                            	<a href="index.php?page=newdetails&id=<?php echo $row['id'];?>"><?php echo $row['newName'];?></a>
                            </td>
                        </tr>
                        <tr>
                        	<td class="datetime_new">
                        		<?php
									echo $row['datecreated'];
								?>
                        	</td>
                        </tr>
                        <tr><td height="2"></td></tr>
                    	<tr>
                        	<td class="title_detail">
                            	<?php
									echo $row['newDetail'];
								?>
                            </td>
                        </tr>
                        <tr>
                        	<td align="right" class="doctiep"><a href="index.php?page=newdetails&id=<?php echo $row['id'];?>">Đọc tiếp</a></td>
                        </tr>
                    </table>	
                </td>
			</tr>
			<tr><td class="news_list" colspan="3">
			</td></tr>
            <?php
			if($a%1==0){
				echo "</tr><tr>";
			}
			$a=$a+1;
            }
			
            ?>
			<tr>
				<td colspan="3" align="center">
					<?php
						if($_GET['pa'] > 1)
						{
							$lui = $_GET['pa'] - 1;
							echo " <a href='index.php?page=news&pa=$lui'>Trang trước</a> ";
						}
						
						for($i=1;$i<=$numOfPage;$i=$i+1)
						{
							if($_GET['pa'] == $i)
							{
								echo "<span class=\"paging\"><a href='index.php?page=news&pa=$i'>".$i."</a></span> | ";	
							}
							else
							{
								echo "<a href='index.php?page=news&pa=$i'>".$i."</a> | ";			
							}
						}
						if($_GET['pa'] < $numOfPage)
						{
							$tien = $_GET['pa'] + 1;
						}
						else
						{
							$tien = 1;	
						}
						echo " <a href='index.php?page=news&pa=$tien'>Trang sau</a>";
					?>
				</td>
			</tr>
	</table>
</body>
</html>